/**
 * Copyright 2011 Snoopy Project 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *      
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.snoopyd.driver;

import java.util.Map;

import org.apache.log4j.Logger;

import com.googlecode.snoopyd.core.Kernel;
import com.googlecode.snoopyd.core.event.ForceStartEvent;
import com.googlecode.snoopymm.ModuleNotFoundException;

public class Moduler extends AbstractDriver implements Driver {

	private static Logger logger = Logger.getLogger(Moduler.class);

	public Moduler(Kernel kernel) {
		super(Moduler.class.getSimpleName(), kernel);
	}

	public Map<String, String> fetch() {
		return kernel.moduleManager().fetch();
	}
	
	public String[] launch(String muid, String[] params) throws com.googlecode.snoopyd.driver.ModuleNotFoundException {
		try {
			return kernel.moduleManager().launch(muid, params);
		} catch (ModuleNotFoundException ex) {
			throw new com.googlecode.snoopyd.driver.ModuleNotFoundException();
		}
	}
	
	public void deploy(String muid, String code) {
		kernel.moduleManager().deploy(muid, code);
	}
	
	public void undeploy(String muid) throws ModuleNotFoundException {
		kernel.moduleManager().undeploy(muid);
	}
	
	public void force(String muid, String[] params) {
		kernel.handle(new ForceStartEvent(muid, params));
	}
}
